#include "../lib/useHead.h"
#include "../lib/stringtable.h"
#include "../lib/functable.h"
#include "../lib/instrStream.h"
#include "../lib/scriptHead.h"
#include "../lib/labelTable.h"
#include "../lib/symTable.h"
#include "../parser/lex.h"
#include "../lib/script.h"
#include "asmCompiler.h"


int main(int argc, char *argv[])
{
    char tName[128], *p;
    ASMCompile com;
    FILE_ERROR_TYPE ret;

    if (argc < 2) {
        fprintf(stderr, "no source file specify!\n");
        exit(1);
    }

    if (argc == 2) {
        p = strchr(argv[1], '.');
        if (p == NULL) {
            strcpy(tName, argv[1]);
        } else {
            memset(tName, 0, sizeof(tName));
            strncpy(tName, argv[1], p - argv[1]);
        }
        strcat(tName, ".xasm"); 
    } else {
        strcpy(tName, argv[2]);
    }

    if(com.compile(argv[1], tName) != 0) {
        printf("compile error!\n");
        exit(1);
    }
        
    printf("compile complete!\n");
    
    com.dump();

    system("pause");
    return 0;
}
